package com.example.gmallcoupon.controller;

import java.util.Arrays;
import java.util.Map;

import com.common.to.SkuReductionTo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.example.gmallcoupon.entity.CouponEntity;
import com.example.gmallcoupon.service.CouponService;
import com.common.utils.PageUtils;
import com.common.utils.R;



/**
 * 优惠券信息
 *
 * @author WDL
 * @email 2329156214@QQ.com
 * @date 2022-05-01 16:19:18
 */
@RestController
@RequestMapping("gmallcoupon/coupon")
public class CouponController {
    @Autowired
    private CouponService couponService;


    @PostMapping("/save/info")
    public R saveSkuReductionInfo(@RequestBody SkuReductionTo skuReductionTo) {
        couponService.saveSkuReductionInfo(skuReductionTo);
        return R.ok();
    }


    @RequestMapping("/test")
    public R testFeign() {
        CouponEntity entity = new CouponEntity();
        entity.setNum(1);
        return R.ok().put("coupon", entity).put("name", "年终大促,买到离手,概不负责");
    }

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = couponService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Long id){
		CouponEntity coupon = couponService.getById(id);

        return R.ok().put("coupon", coupon);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody CouponEntity coupon){
        couponService.save(coupon);
        return R.ok();
    }


    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody CouponEntity coupon){
		couponService.updateById(coupon);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] ids){
		couponService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
